package com.cxg.fairy.ec.detail;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ui.recycler.DataConverter;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/4/10.
 */

public class CommentActionDataConverter extends DataConverter{

    @Override
    public ArrayList<MultipleItemEntity> convert() {

            final JSONArray array = JSON.parseObject(getJsonData()).getJSONArray("data");
            final int size = array==null?0:array.size();
            for (int i = 0; i < size; i++) {

                final JSONObject data = array.getJSONObject(i);
                final int skuId = data.getInteger("skuId");
                final String goodsName = data.getString("goodsName");
                final double sellPrice = data.getDouble("sellPrice");
                final String thumb = data.getString("thumb");

                final MultipleItemEntity entity = MultipleItemEntity.builder()
                        .setField("goodsName", goodsName)
                        .setField("skuId", skuId)
                        .setField("sellPrice", sellPrice)
                        .setField("thumb", thumb)
                        .build();
                ENTITIES.add(entity);
            }

            return ENTITIES;
        }

    @Override
    public MultipleItemEntity convertHeader() {
        return null;
    }
}
